package com.roger.tool.json;

import org.json.JSONArray;
import org.json.JSONException;

public class KJSONArray extends JSONArray {

	private KJSONArray() {
		super();
	}

	private KJSONArray(String json) throws JSONException {
		super(json);
	}

	public static KJSONArray createJsonArray(String json) {
		try {
			return new KJSONArray(json);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static KJSONArray createJsonArray() {
		return new KJSONArray();
	}

	@Override
	public Object get(int index) {
		try {
			return super.get(index);
		} catch (Exception e) {
			return null;
		}
	}

	public Object get(int index, Object defaultValue) {
		try {
			return super.get(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public boolean getBoolean(int index) {
		try {
			return super.getBoolean(index);
		} catch (Exception e) {
			return false;
		}
	}

	public boolean getBoolean(int index, boolean defaultValue) {
		try {
			return super.getBoolean(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public double getDouble(int index) {
		try {
			return super.getDouble(index);
		} catch (Exception e) {
			return 0.0d;
		}
	}

	public double getDouble(int index, double defaultValue) {
		try {
			return super.getDouble(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public int getInt(int index) {
		try {
			return super.getInt(index);
		} catch (Exception e) {
			return 0;
		}
	}

	public int getInt(int index, int defaultValue) {
		try {
			return super.getInt(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public JSONArray getJSONArray(int index) {
		try {
			return super.getJSONArray(index);
		} catch (Exception e) {
			return null;
		}
	}

	public JSONArray getJSONArray(int index, JSONArray defaultValue) {
		try {
			return super.getJSONArray(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public KJSONObject getJSONObject(int index) {
		try {
			return KJSONObject.createJsonObject(super.getJSONObject(index).toString());
		} catch (Exception e) {
			return null;
		}
	}

	public KJSONObject getJSONObject(int index, KJSONObject defaultValue) {
		try {
			return KJSONObject.createJsonObject(super.getJSONObject(index).toString());
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public long getLong(int index) {
		try {
			return super.getLong(index);
		} catch (Exception e) {
			return 0;
		}
	}

	public long getLong(int index, long defaultValue) {
		try {
			return super.getLong(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public String getString(int index) {
		try {
			return super.getString(index);
		} catch (Exception e) {
			return null;
		}
	}

	public String getString(int index, String defaultValue) {
		try {
			return super.getString(index);
		} catch (Exception e) {
			return defaultValue;
		}
	}

	@Override
	public JSONArray put(int index, boolean value) {
		try {
			return (KJSONArray) super.put(index, value);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public JSONArray put(int index, double value) {
		try {
			return (KJSONArray) super.put(index, value);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public JSONArray put(int index, int value) {
		try {
			return (KJSONArray) super.put(index, value);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public JSONArray put(int index, long value) {
		try {
			return (KJSONArray) super.put(index, value);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public KJSONArray put(int index, Object value) {
		try {
			return (KJSONArray) super.put(index, value);
		} catch (Exception e) {
			return null;
		}
	}

}
